#include <cstdlib> 
#include <cstdio> 
#include <iostream>
#include <mysql.h>
using namespace std;
main()
{    
    MYSQL *conn;    
    MYSQL_RES *res;    
    MYSQL_ROW row;    

    char *server = "172.16.10.10";    
    char *user = "babytree";    
    char *password = "babytree";  //是我自己后来改的密码，修改成功了
    char *database = "test";    

    conn = mysql_init(NULL);    

    /* Connect to database */    
    if (!mysql_real_connect(conn, server,    
                user, password, database, 0, NULL, CLIENT_MULTI_STATEMENTS)) {    
        fprintf(stderr, "open error:%s\n", mysql_error(conn));    
        exit(1);    
    }    

    string sqlStr = "INSERT INTO Similarity(qId1,qId2,lsa) VALUES(100010,181285,0.283324); \
    INSERT INTO Similarity(qId1,qId2,lsa) VALUES(100010,289745,0.283254);\
    INSERT INTO Similarity(qId1,qId2,lsa) VALUES(100010,275040,0.283239);";
    /* send SQL query */    
    if (mysql_query(conn, sqlStr.c_str())) {    
        fprintf(stderr, "%s\n", mysql_error(conn));    
        exit(1);    
    }    

    res = mysql_use_result(conn);    

    /* output table name */    
    printf("MySQL Tables in mysql database:\n");    
    while ((row = mysql_fetch_row(res)) != NULL)    
        printf("%s \n", row[0]);    

    /* close connection */    
    mysql_free_result(res);    
    mysql_close(conn);    
}   
